package com.explorati.LinkedList.LeetCode206;

public class Solution {

	private String generateDepthString(int depth) {
		StringBuilder res = new StringBuilder();
		for (int i = 0; i < depth; i++) {
			res.append("---");
		}
		return res.toString();
	}

	public ListNode reverseListNode(ListNode head, int depth) {

		String generateDepthString = generateDepthString(depth);
		System.out.print(generateDepthString);
		System.out.println("Call , reverseListNode: " + head);
		if (head == null) {
			return null;
		}
		if (head.next == null) {
			System.out.print(generateDepthString);
			System.out.println("Return : " + head);
			return head;
		}

		ListNode reverse_head_next = reverseListNode(head.next, depth + 1);

		System.out.print(generateDepthString);
		System.out.println("After reverse :" + head);
		ListNode reverse_tail = reverse_head_next;
		while (reverse_tail.next != null) {
			reverse_tail = reverse_tail.next;
		}
		reverse_tail.next = head;
		head.next = null;
		System.out.print(generateDepthString);
		System.out.println("Return :" + reverse_head_next);

		// ListNode reverse_tail = head.next;
		// reverse_tail.next = head;
		//
		// head.next = null;
		return reverse_head_next;

		// ListNode cur = head;
		// if(cur != null){
		// cur.next = null;
		// head = head.next;
		// }
		//
		//
		// ListNode prev = head;
		//
		// while(prev != null){
		// ListNode next = prev.next;
		// prev.next = cur;
		// head = prev;
		// prev = next;
		// }
		//
		// return head;
		//

	}
}
